import VueRouter from 'vue-router' 
import index from '../papes/index.vue'
import login from '../papes/login.vue'
import secondsheets from '../papes/secondsheets.vue'
import home from '../papes/content/home.vue'
import article from '../papes/content/Article.vue'
import Course from '../papes/content/Course.vue'
import tacher from '../papes/content/tacher.vue'
import CourseDetails from '../papes/details/CourseDetails.vue'
import ThatPerson from '../papes/details/ThatPerson.vue'
import searchresul from '../papes/details/searchresult.vue'
import PersonalInformation from '../papes/details/dop_details/PersonalInformation.vue'
import mycourse from '../papes/details/dop_details/mycourse.vue'
import ArticleContent from '../papes/details/ArticleContent.vue'

//解决vue路由重复导航错误
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

export default new VueRouter({

     routes:[
        //登录
        {
            path:'/login',
            component:login
        },
        //主页
        {
            
            path:'/index',
            component:index,
            children:[
                {
                    path:'home',
                    component:home
                },
                {
                    path:'course',
                    component:Course,
                },
                {
                    path:'article',
                    component:article,
                },
                {
                    path:'tacher',
                    component:tacher
                },
               
            ]
        },
        //副页
        {
            path:'/secondsheets',
            component:secondsheets,
            children:[
                {
                    path:'CourseDetails',
                    component:CourseDetails,
                },
                {
                    path:'ArticleContent',
                    component:ArticleContent
                },
                {
                    path:'searchresul',
                    component:searchresul
                },
                {
                    path:'ThatPerson',
                    component:ThatPerson,
                    children:[
                        {
                            path:'/',
                            redirect:'/secondsheets/ThatPerson/PersonalInformation',
                            

                        },
                        {
                            path:'mycourse',
                            component:mycourse
                        },
                        {
                            path:'PersonalInformation',
                            component:PersonalInformation,
                            meta: { isAuth: true },
                            beforeEnter: (to, from, next) => {
                            if (to.meta.isAuth) { //判断是否需要授权
                                var Loginstate=sessionStorage.getItem('Loginstate')
                            if (Loginstate === '1') {
                                next()  //放行
                            } else {
                                console.log(this)
                                console.log(Loginstate)
                                alert('请登录后在访问该页面');
                                }
                            } else {
                                next()  //放行
                                }
                            }
                        },

                    ]
                },
            ]
        },
        {
            path:'/',
            redirect:'/index/home'
        },
     ]
})
